import Mock, { Random } from "mockjs";
Mock.setup({
  timeout: "100-400",
});
Mock.mock("/admin/base/open/login", "post", (params) => {
  const { username } = JSON.parse(params.body);
  if (username === "admin") {
    return {
      code: 1000,
      data: {
        roles: ["userManage", "activityManage"],
        token: "eqedsadbakshdasnxanjksdandlkasjdnanxkasldnas",
      },
      message: "",
    };
  }
  return {
    code: 1000,
    data: {
      roles: ["activityManage"],
      token: "eqedsadbakshdasnxanjksdandlkasjdnanxkasldnasasda",
    },
    message: "",
  };
});
const test = Mock.mock({
  "data|45": [
    {
      "id|+1": 0,
      activityName: "@ctitle",
      activityImg: '@image("200x200", "#FF6600", "hello")',
      "activityStatus|1-3": 1,
      "activityMax|100-150": 1,
      "activityRegistered|50-99": 1,
      address: "@county(true)",
      activitStartDate: '@date("yyyy-MM-dd")',
      activitEndDate: '@date("yyyy-MM-dd")',
      business: "@cname",
      detail: "@cparagraph(45)",
    },
  ],
});

Mock.mock("/admin/base/getActivityList", "post", (params) => {
  let filter = JSON.parse(params.body);
  const filterData = test.data.filter((el: any) => {
    return (
      (!filter.activityStatus || el.activityStatus === filter.activityStatus) &&
      (!filter.activityName || el.activityName.includes(filter.activityName))
    );
  });
  return {
    code: 1000,
    data: {
      total: filterData?.length,
      data: filterData,
    },
  };
});
Mock.mock("/admin/base/getActivityList", "delete", (params) => {
  let body = JSON.parse(params.body);
  test.data = body.reduce((pre: any, cur: any) => {
    return pre.filter((item: any) => item.id !== cur);
  }, test.data);
  return {
    code: 1000,
    data: {
      total: body?.length,
      data: {
        success: true,
      },
    },
  };
});
Mock.mock("/admin/base/activityManage/new", "post", (params) => {
  let body = JSON.parse(params.body);
  test.data = body.reduce((pre: any, cur: any) => {
    return pre.filter((item: any) => item.id !== cur);
  }, test.data);
  return {
    code: 1000,
    data: {
      total: body?.length,
      data: {
        success: true,
      },
    },
  };
});
